<script setup lang="ts">
import { ref, computed } from 'vue'
import { useRoute } from 'vue-router'
import Sidebar from './components/layout/Sidebar.vue'

const route = useRoute()
const isSidebarOpen = ref(false)

const showSidebar = computed(() => {
  return route.path !== '/login'
})

const toggleSidebar = () => {
  isSidebarOpen.value = !isSidebarOpen.value
}

const closeSidebar = () => {
  isSidebarOpen.value = false
}
</script>

<template>
  <div class="app-container">
    <!-- 只在非登录页显示侧边栏和菜单按钮 -->
    <template v-if="showSidebar">
      <button class="menu-toggle" @click="toggleSidebar" aria-label="Toggle menu">
        <span class="menu-icon">☰</span>
      </button>
      
      <Sidebar 
        :class="{ 'sidebar-open': isSidebarOpen }" 
        @close="closeSidebar"
      />
    </template>
    
    <main :class="['main-content', { 'with-sidebar': showSidebar }]">
      <div class="page-container">
        <router-view></router-view>
      </div>
    </main>
  </div>
</template>

<style>
.app-container {
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  background: #ffffff;
}

.main-content.with-sidebar {
  margin-left: 240px;
}

.page-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
  width: 100%;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'JetBrains Mono', monospace;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #374151;
}

/* 代码块使用相同字体 */
pre, code {
  font-family: 'JetBrains Mono', monospace;
}

/* 响应式布局 */
@media (max-width: 768px) {
  .app-container {
    position: relative;
    width: 100%;
    overflow-x: hidden;  /* 防止水平滚动 */
  }

  .main-content {
    margin-left: 0;
    padding-top: 4rem;
    width: 100%;
    overflow-x: hidden;
  }

  .main-content.with-sidebar {
    margin-left: 0;
  }

  .page-container {
    padding: 0;  /* 移除内边距 */
    width: 100%;
    max-width: 100%;
  }

  .menu-toggle {
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1000;
    background: white;
    border: none;
    padding: 0.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    cursor: pointer;
  }

  .menu-icon {
    font-size: 1.5rem;
    line-height: 1;
  }

  .sidebar {
    position: fixed;
    left: -240px;
    top: 0;
    bottom: 0;
    transition: left 0.3s ease;
    z-index: 100;
  }

  .sidebar-open {
    left: 0;
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
  }

  @media (max-width: 768px) {
    .sidebar-open + .sidebar-backdrop {
      display: block;
    }
  }

  .menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
  }
}

.menu-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 1000;
  background: white;
  border: none;
  padding: 0.5rem;
  border-radius: 0.5rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  cursor: pointer;
}

@media (max-width: 768px) {
  .menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
  }

  .main-content {
    margin-left: 0;
    padding-top: 4rem;
  }
}

/* 全局滚动条样式 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
  transition: all 0.2s;
}

::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* Firefox 滚动条样式 */
* {
  scrollbar-width: thin;
  scrollbar-color: #d1d5db transparent;
}

/* 隐藏特定元素的滚动条但保持可滚动 */
.hide-scrollbar {
  -ms-overflow-style: none;  /* IE and Edge */
  scrollbar-width: none;  /* Firefox */
}

.hide-scrollbar::-webkit-scrollbar {
  display: none;  /* Chrome, Safari and Opera */
}

/* 移动端优化 */
@media (max-width: 768px) {
  ::-webkit-scrollbar {
    width: 4px;
    height: 4px;
  }
}

/* 聊天输入框容器样式 */
.chat-input-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  padding: 1rem;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  z-index: 100;
}

/* 确保主内容区域不被固定的输入框遮挡 */
@media (max-width: 768px) {
  .page-container {
    padding-bottom: 80px;
  }
}
</style>
